import pymysql
class DB:
    def __init__(self):
        self.conn=pymysql.connect(host='localhost',port=3306,user='root',password='root',db='test',charset='utf8',cursorclass=pymysql.cursors.DictCursor)
        self.cursor=self.conn.cursor()
    # 修改
    def update(self,sql):
        self.cursor.execute(sql)
        self.conn.commit()
    # 添加
    def insert(self,sql):
        self.cursor.execute(sql)
        self.conn.commit()
    # 删除
    def delete(self,sql):
        self.cursor.execute(sql)
        self.conn.commit()
    # 查询一条
    def find(self,sql):
        self.cursor.execute(sql)
        return self.cursor.fetchone()
    # 查询所有
    def findall(self,sql):
        self.cursor.execute(sql)
        return self.cursor.fetchall()
    #关闭
    def close(self):
        self.cursor.close()
        self.conn.close()
db1=DB()